package com.tadpole.music.holder.home;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;
import com.tadpole.music.bean.home.ClockInRankBean;
import com.tadpole.music.config.Constant;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.view.widget.NiceImageView;

/**
 * Created By 孙岩
 * on 2020/12/9
 */
public class RankViewHolder extends BaseViewHolder {
    private View itemView;
    private Activity activity;
    private ImageView ivHuangguang;
    private TextView tvNumber;
    //头像
    private NiceImageView ivImage;
    //姓名
    private TextView tvName;
    //自己 你已经累计打卡  别人 累计打卡
    private TextView tvText;
    //天数
    private TextView tvClockDay;
    //背景
    private RelativeLayout rlMe;
    //数据源
    private ClockInRankBean.DataBean dataBean;

    public RankViewHolder(Activity activity, View itemView, ClockInRankBean.DataBean dataBean) {
        super(itemView);
        this.activity = activity;
        this.itemView = itemView;
        this.dataBean = dataBean;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void init(int position) {
        ivHuangguang = itemView.findViewById(R.id.ivHuangguang);
        tvNumber = itemView.findViewById(R.id.tvNumber);
        tvName = itemView.findViewById(R.id.tvName);
        ivImage = itemView.findViewById(R.id.ivImage);
        rlMe = itemView.findViewById(R.id.rlMe);
        tvText = itemView.findViewById(R.id.tvText);
        tvClockDay = itemView.findViewById(R.id.tvClockDay);

        if (position == 0) {
            ivHuangguang.setVisibility(View.VISIBLE);
            tvNumber.setVisibility(View.GONE);
            ivHuangguang.setImageResource(R.mipmap.huangguang1);
        } else if (position == 1) {
            ivHuangguang.setVisibility(View.VISIBLE);
            tvNumber.setVisibility(View.GONE);
            ivHuangguang.setImageResource(R.mipmap.huangguang2);
        } else if (position == 2) {
            ivHuangguang.setVisibility(View.VISIBLE);
            tvNumber.setVisibility(View.GONE);
            ivHuangguang.setImageResource(R.mipmap.huangguang3);
        } else {
            ivHuangguang.setVisibility(View.GONE);
            tvNumber.setVisibility(View.VISIBLE);
            tvNumber.setText((position + 1) + "");
        }

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.app_icon)
                .error(R.mipmap.app_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);

        Glide.with(activity).load(dataBean.getList().get(position).getSign().getUser().getAvatar()).apply(requestOptions).into(ivImage);

        if(dataBean.getList().get(position).getSign().getUser().getNickname().equals("")){
            tvName.setText("蝌蚪会员");
        }else{
            tvName.setText(dataBean.getList().get(position).getSign().getUser().getNickname());
        }

        tvClockDay.setText(dataBean.getList().get(position).getSign().getTotal_sign_days()+"");

        if(dataBean.getList().get(position).isIs_me()){
            tvText.setText("累计签到");
            tvClockDay.setTextColor(activity.getResources().getColor(R.color.color_me));
            rlMe.setBackgroundColor(activity.getResources().getColor(R.color.color_rili));
        }else{
            tvText.setText("累计签到");
            tvClockDay.setTextColor(activity.getResources().getColor(R.color.color_other));
            rlMe.setBackgroundColor(activity.getResources().getColor(R.color.white));
        }
    }
}
